# AdaBoost
# 
# Author: Fatih Sunor
#################################################

while(i<=500){ 
	w<-exp(-y*f);
	w<-w/sum(w);
	fit<-rpart(y~.,x,w,method="class");
	g<--1+2*(predict(fit,x)[,2]>.5); # make -1 or 1 
	g_test<--1+2*(predict(fit,x_test)[,2]>.5); 
	e<-sum(w*(y*g<0));
	alpha<-.5*log((1-e)/e);
	alpha<-.1*alpha;
	f<-f+alpha*g;
	f_test<-f_test+alpha*g_test;
	train_error[i]<-sum(1*f*y<0)/130;
	test_error[i]<-sum(1*f_test*y_test<0)/78;
	i<-i+1;
}